<%
  # Views that use this partial must provide the following variable:
  # comment
  #
  new_record = comment.new_record?

  # Optionally, they can also supply the following variables:
  thread ||= new_record ? comment.thread : nil
  no_remote ||= false
%>

<% config = comment.thread.config %>

<% if comment.errors.any? %>
  <div class="error-message">
    <h6><%= t "commontator.comment.errors.#{new_record ? 'create' : 'update'}" %></h6>

    <ul>
      <% comment.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
    </ul>
  </div>
<% end %>

<%= form_for([commontator, thread, comment], remote: !no_remote) do |form| %>
  <%= form.hidden_field :parent_id %>

  <% unless comment.parent.nil? %>
    <div class="replying">
      <%= t("commontator.comment.status.replying",
            creator_name: Commontator.commontator_name(comment.parent.creator)) %>
    </div>
  <% end %>

  <div class="comments-field">
    <%=
      form.text_area :body, rows: '4', id: new_record ?
        comment.parent.nil? ? "commontator-thread-#{@commontator_thread.id}-new-comment-body" :
                              "commontator-comment-#{comment.parent.id}-reply" :
        "commontator-comment-#{comment.id}-edit-body",class:"form-control"
    %>
  </div>

  <div class="submit">
    <%= form.submit t("commontator.comment.actions.#{new_record ? 'create' : 'update'}"), class: "btn primary-button" %>
    <%=
      form.submit(
        t('commontator.comment.actions.cancel'), name: 'cancel', class: "btn primary-button"
      ) unless config.new_comment_style == :t && new_record && comment.parent.nil?
    %>
  </div>
<% end %>
